@extends('layouts.app')
@include('user.sidebar')
@section('content')
    <div class="content">
        <div class="row custom-invoice">
            <div class="">
                <form id="select-form" class="form form-inline" method="" action="">
                    <div class="form-group">
                        <input class="form-control" type="text" name="search" id="" value="{{ $search }}" placeholder="电话/姓名/昵称">
                    </div>
                    <button type="button" class="btn btn-success select-button" data-action="{{ route('admin.user.all') }}" value="">搜索</button>
                </form>
            </div>
            <br />

            <br />
            <span>数量：{{ $count }} </span>
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th style="min-width: 80px;">真实姓名</th>
                    <th style="min-width: 100px;">昵称</th>
                    <th style="min-width: 50px;">头像</th>
                    <th style="min-width: 90px;">身份</th>
                    <th style="min-width: 90px;">电话号</th>
                    <th style="min-width: 100px;">首次登陆时间</th>
                    <th style="min-width: 100px;">最近登陆时间</th>
                    <th style="min-width: 400px;">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <td>{{ $item->name }}</td>
                        <td><a href="{{ route('admin.order.good_index', ['referrer_id' => $item->id]) }}" target="_blank">{{ $item->nickname }}</a></td>
                        <td><img src="{{ $item->avatar }}" width="30"></td>
                        <td>{{ \App\Modules\User\Models\User::$levelShow[$item->level] }}</td>
                        <td>{{ $item->mobile }}</td>
                        <td>{{ $item->created_at }}</td>
                        <td>{{ $item->last_time }}</td>
                        <td>
                            @can("recharge_record_recharge")
                                <a class="btn btn-primary btn-xs" href="{{ route('admin.rechargeRecord.recharge',['user_id' => $item->id]) }}"><i class="fa fa-edit"></i> 充值</a>
                            @endcan

                            @can("user-all-edit")
                            <a class="btn btn-primary btn-xs" href="{{ route('admin.user.edit', ['id' => $item->id, 'level' => $item->level]) }}"><i class="fa fa-edit"></i> 编辑</a>
                            @endcan

                            @can("user-all-jump")
                                @if($item->level == 0)
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.user.index', ['level' => $item->level, 'search' => $item->name]) }}"><i class="fa fa-hand-o-right"></i> 跳转</a>
                                @elseif($item->level == 1)
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.user.index', ['level' => $item->level, 'search' => $item->name]) }}"><i class="fa fa-hand-o-right"></i> 跳转</a>
                                @elseif($item->level == 2)
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.user.index', ['level' => $item->level, 'search' => $item->name]) }}"><i class="fa fa-hand-o-right"></i> 跳转</a>
                                @elseif($item->level == 3)
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.user.staff', ['search' => $item->name]) }}"><i class="fa fa-hand-o-right"></i> 跳转</a>
                                @endif
                            @endcan
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->appends(['search' => $search, 'searchReferrer' => $searchReferrer, 'level' => $level])->links() }}
        </div>

    </div>
@endsection
@push("stylesheets")
    <style>
        .select2-container--default .select2-selection--multiple .select2-selection__choice {
            color: gray;
        }
    </style>
@endpush
@push('scripts')
    <script>
        $('#shop_id.select2').select2({width: "100%"});
        // $('#start').datetimepicker({format:"YYYY-MM-DD"});
        // $('#end').datetimepicker({format:"YYYY-MM-DD"});
        $("#start").datetimepicker({format: "Y-m-d",timepicker:false});
        $("#end").datetimepicker({format: "Y-m-d",timepicker:false});
        $.datetimepicker.setLocale('zh');

        $('.changeLevel').on('click', function () {
            $("#hideForm form").attr('action', $(this).attr('data-url'));
            var level = $(this).attr('data-level');
            $("#level").find("option[value='"+ level +"']").attr('selected', true);
            $("#hideForm").modal('show');
        });
        $('#closeHideForm').on('click', function () {
            $("#hideForm").modal('hide');
        });

        // $('.changePersonal').on('click', function () {
        //     $("#hideForm2 form").attr('action', $(this).attr('data-url'));
        //     $("#hideForm2").modal('show');
        // });
        // $('#closeHideForm2').on('click', function () {
        //     $("#hideForm2").modal('hide');
        // });

        $('.changeReferrer').on('click', function () {
            $("#hideForm3 form").attr('action', $(this).attr('data-url'));
            $("#hideForm3").modal('show');
        });
        $('#closeHideForm3').on('click', function () {
            $("#hideForm3 form").attr('action', $(this).attr('data-url'));
            $("#hideForm3").modal('hide');
        });

        $('.batchChangeReferrer').on('click', function () {
            $("#hideForm4").modal('show');
        });

        $('#level').on('change', function () {
            if ($(this).val() == 3) {
                $('#identity-div').removeClass('hidden');
            } else {
                $('#identity-div').addClass('hidden');
            }
        });

        $('.update-referrer').select2({
            ajax: {
                dataType: 'json',
                delay: 250,
                url: function () {
                    return '{{ route('admin.search_user', ['level' => 3]) }}';
                },
                processResults: function (data) {
                    return {
                        results: $.map(data, function(row, key) {
                            return {
                                id: key,
                                text: row
                            };
                        })
                    };
                }
            }
        });

        $(".select-button").on('click', function () {
            var form = $("#select-form");
            form.attr('method', 'get');
            form.attr('action', $(this).data('action'))
            form.submit();
        });
        $(".export").on('click', function () {
            $(this).prop('disabled', true);
            var form = $("#select-form");
            form.attr("method", "POST");
            form.attr('action', $(this).data('action'))
            form.submit();
        });
    </script>
@endpush
